<?php
	include("global.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link href="css/main.css" rel="stylesheet" type="text/css" />
<link href="css/div.css" rel="stylesheet" type="text/css" />
<script src="js/jquery.js" language="javascript" type="text/javascript"></script>
<script src="js/jquery-1.4.2.js" language="javascript" type="text/javascript"></script>
<script src="js/secondmenu.js" language="javascript" type="text/javascript"></script>
<script type="text/javascript">

</script>
<style type="text/css">
.pages { height:25px; overflow:hidden; text-align:center; line-height:25px; font-family:Verdana; }
.pages a, .pages strong { margin:0 1px; padding:2px 6px; border:1px solid #E4E4E4; text-decoration:none!important; }
.pages a:hover { border-color:#369; color:369 }
.backs { border-color:#369; background:#369; color:#FFF; }
.pages .prev { padding:4px 6px 2px 20px!important; padding:4px 6px 0 20px; background:url(images/arrow_left.gif) no-repeat 9% 50%; font-family:simsun; }
.next { padding:4px 20px 2px 6px!important; padding:4px 20px 0 6px; background:url(images/arrow_right.gif) no-repeat 91% 50%; font-family:simsun; }
</style>
<script type="text/javascript">
	$(function(){
		$("#fenye a").click( function() {
			$(this).addClass("backs");
		});
	});	 
</script>

</head>
<?php
	include("conn/conn.php");
?>
<body>
<div class="box1">
	<?php include("top.php"); ?>
	<embed src="diy/pics/20100623/1.swf" width="1002" height="254" style="position: absolute; left: 18%; top: 130px;"  quality="high" wmode="transparent"  />
			<img src="diy/pics/20100623/chanpinzhanshi1.png" border="0" width="1002" />
		  </div>
		</div>
		<div style=" height:10px;">&nbsp;</div>
	
	<div style=" height:20px;">&nbsp;</div>
	<div style=" width:1003px;">
		<div style=" width:200px; overflow:hidden; float:left;">
			
			<?php
				include("productstree.php");
				include("search.php");
				if(isset($_GET["id"])){
					$ids = $_GET["id"];
					if($ids==1){
						$sql1 = mysql_query("select count(*) as counts from `products` where id_category=1");
						$counts =  mysql_result($sql1,0,"counts");
						$page = intval($counts/12);		
						if (isset($_GET["pages"])) {
							$pages = $_GET["pages"];
							$sql = mysql_query("SELECT files,name,id FROM `products`  where id_category=1 order by id desc LIMIT ".(12*$pages).", 12 ");
						}else{
							$sql = mysql_query("SELECT files,name,id FROM `products` where id_category=1 order by id desc LIMIT 0, 12 ");
						}
					}
					if($ids==2){
						$sql1 = mysql_query("select count(*) as counts from `products` where id_category=2");
						$counts =  mysql_result($sql1,0,"counts");
						$page = intval($counts/12);		
						if (isset($_GET["pages"])) {
							$pages = $_GET["pages"];
							$sql = mysql_query("SELECT files,name,id FROM `products`  where id_category=2 order by id desc LIMIT ".(12*$pages).", 12 ");
						}else{
							$sql = mysql_query("SELECT files,name,id FROM `products` where id_category=2 order by id desc LIMIT 0, 12 ");
						}
					}
				}else{
					$sql1 = mysql_query("select count(*) as counts from `products`");
					$counts =  mysql_result($sql1,0,"counts");
					$page = intval($counts/12);		
					if (isset($_GET["pages"])) {
						$pages = $_GET["pages"];
						$sql = mysql_query("SELECT files,name,id FROM `products` order by id desc LIMIT ".(12*$pages).", 12 ");
					}else{
						$sql = mysql_query("SELECT files,name,id FROM `products` order by id desc LIMIT 0, 12 ");
					}
				}
			?>
		</div>
		<div style="float:left; width:50px;">&nbsp;</div>
		<div style=" float:left; width:750px;">
			<div style=" width: 750px; background-color:#8DBAE0; height:5px;"></div>
			<div style=" width:200px; height:15px;">&nbsp;</div>
			<div style=" width:750px; height:20px;">
				<span style=" float:left; text-align:left;color:#768DC1; font-size:15px; font-weight:bolder; height:30px;"><?php if($ids==1) echo "药品"; else if($ids==2) echo "保健品"; else echo "产品展示";?></span><span style=" float:right;text-align:right" id="span1"><a href="index.php">首页</a>-><a href="products.php">产品展示</a>-><a href="products.php<?php if($ids==1 || $ids==2) echo "?id=".$ids; ?>"><?php if($ids==1) echo "药品"; else if($ids==2) echo "保健品"; else echo "产品展示";?></a></span>
			</div>
			<div style=" height:10px;">&nbsp;</div>
			<div style=" width:750px; text-align:center; height:460px;">
			<?php 
				if(isset($_GET["id"])){
					$ids = $_GET["id"];
					if($ids==1){
						$sql1 = mysql_query("select count(*) as counts from `products` where id_category=1");
						$counts =  mysql_result($sql1,0,"counts");
						$page = intval($counts/12);		
						if (isset($_GET["pages"])) {
							$pages = $_GET["pages"];
							$sql = mysql_query("SELECT files,name,id FROM `products`  where id_category=1 order by id desc LIMIT ".(12*$pages).", 12 ");
						}else{
							$sql = mysql_query("SELECT files,name,id FROM `products`  where id_category=1 order by id desc LIMIT 0, 12 ");
						}
					}
					else if($ids==2){
						$sql1 = mysql_query("select count(*) as counts from `products` where id_category=2");
						$counts =  mysql_result($sql1,0,"counts");
						$page = intval($counts/12);		
						if (isset($_GET["pages"])) {
							$pages = $_GET["pages"];
							$sql = mysql_query("SELECT files,name,id FROM `products`  where id_category=2 order by id desc LIMIT ".(12*$pages).", 12 ");
						}else{
							$sql = mysql_query("SELECT files,name,id FROM `products`  where id_category=2 order by id desc LIMIT 0, 12 ");
						}
					}else{
						$sql1 = mysql_query("select count(*) as counts from `products`");
						$counts =  mysql_result($sql1,0,"counts");
						$page = intval($counts/12);		
						if (isset($_GET["pages"])) {
							$pages = $_GET["pages"];
							$sql = mysql_query("SELECT files,name,id FROM `products` order by id desc LIMIT ".(12*$pages).", 12 ");
						}else{
							$sql = mysql_query("SELECT files,name,id FROM `products` order by id desc LIMIT 0, 12 ");
						}
					}
				}
				if(isset($_GET["submitzd"])){
					$zdye = $_GET["pages"];
					if($zdye == ""){
						$zdye = 1;
					}
					if($ids == 1){
						$sql = mysql_query("select files,name,id FROM `products` where id_category=1  order by id desc LIMIT ".(12*($zdye-1)).", 12");
					}else if($ids == 2){
						$sql = mysql_query("select files,name,id FROM `products`  where id_category=2 order by id desc LIMIT ".(12*($zdye-1)).", 12");
					}else{
						$sql = mysql_query("select files,name,id FROM `products` order by id desc LIMIT ".(12*($zdye-1)).", 12");
					}
				}
				while($row=mysql_fetch_array($sql)) {
 			?>
				<div style=" width:140px; height:140px;float:left; margin:0px 0px 10px 0px;">
					<a href="productsdetail.php?ids=<?php echo $row[2] ?>">
						<div style="height:100px;"><img src="<?php echo $row[0]; ?>" width="140" height="100" style=" border-bottom:1px dashed #999"></div>
						<div style=" line-height:40px; height:40px;"><?php echo $row[1] ?></div>
					</a>
				</div>
				<div style=" width:30px; float:left">&nbsp;</div>
				<?php } ?>
			</div>
			<div style=" height:20px; clear:both;">&nbsp;</div>
			
			<div class="pages" id="fenye">
			<form action="" method="get" name="form2">
				<?php 
					$nexts = "";
					$pres = "";
					$zhiding = "";
					//上一页
				
					if(isset($_GET["pages"])){
						if(isset($_GET["submitzd"])){
							$pages = $_GET["pages"];
							$pages = $pages-1;
						}
						if($pages == 0)
							$pres = "<a href='javascript:window.location.reload();' class='next'>上一页</a>";
						else
							$pres = "<a href='products.php?pages=".($pages-1)."&id=".$ids."' class='next'>上一页</a>";
					}else{
						$pres = "<a href='javascript:window.location.reload();' class='next'>上一页</a>";
					}
					echo $pres;
					
					//数字
					for($i=0;$i<=$page;$i++){
						if (isset($_GET["pages"])) {
							if(isset($_GET["submitzd"])){
								$pages = $_GET["pages"];
								$pages = $pages-1;
							}
							if($i==$pages){
								echo "<a href='products.php?pages=".$i."&id=".$ids."' class='backs'>".($i+1)."</a>";		
							}else{
								echo "<a href='products.php?pages=".$i."&id=".$ids."'>".($i+1)."</a>";
							}
							
						}else{
							if($i==$page){
								echo "<a href='products.php?pages=".$i."&id=".$ids."'>".($i+1)."</a>";		
							}else{
								echo "<a href='products.php?pages=".$i."&id=".$ids."'>".($i+1)."</a>";
							}
						}
					}
					
					if(isset($_GET["pages"])){
						if(isset($_GET["submitzd"])){
								$pages = $_GET["pages"];
								$pages = $pages-1;
							}
						if($pages == $page)
							$nexts = "<a href='javascript:window.location.reload();' class='next'>下一页</a>";
						else
							$nexts = "<a href='products.php?pages=".($pages+1)."&id=".$ids."' class='next'>下一页</a>";
					}else{
						$nexts = "<a href='products.php?pages=1&id=".$ids."' class='next'>下一页</a>";
					}
					echo $nexts;
					
					//指定页
					$zhiding = "到<input type='text' style=' border:1px solid #333; width:25px;' id='pages' name='pages' /><input type='hidden' name='id' value='".$ids."'><input type='submit' value='确定' name='submitzd'>";
					echo $zhiding;
				?>
				</form>
			</div>

		</div>
	</div>
	<?php include("foot.php"); ?>
</div>
</body>
</html>

